/**
 * 用来加工处理最终用户消息的模板
 *
 */
module.exports = options => {
    //  将消息回复格式通用部分提取出来
    let replyMessage = `<xml>
              <ToUserName><![CDATA[${options.ToUserName}]]></ToUserName>
              <FromUserName><![CDATA[${options.FromUserName}]]></FromUserName>
              <CreateTime>${options.createTime}</CreateTime>
              <MsgType><![CDATA[options.msgType]]></MsgType>`;

    if(options.msgType === 'text'){
        replyMessage += `<Content><![CDATA[${options.content}]]></Content>`;
            
    }else if(options.msgType === 'image'){
        replyMessage += `<Image>
                            <MediaId><![CDATA[${options.media_id}]]></MediaId>
                        </Image>`;
    }else if(options.msgType === 'voice'){
        replyMessage += `<Voice>
                            <MediaId><![CDATA[${options.media_id}]]></MediaId>
                          </Voice>`;
    }else if(options.msgType === 'voice'){
        replyMessage += `<Video>
                                <MediaId><![CDATA[[${options.media_id}]]></MediaId>
                                <Title><![CDATA[[${options.title}]]></Title>
                                <Description><![CDATA[[${options.description}]]></Description>
                          </Video>`;
    }else if(options.msgType === 'music'){
        replyMessage += `<Music>
                            <Title><![CDATA[[${options.title}]]></Title>
                            <Description><![CDATA[[${options.description}]]></Description>
                            <MusicUrl><![CDATA[${options.MUSIC_Url}]]></MusicUrl>
                            <HQMusicUrl><![CDATA[${options.HQ_MUSIC_Url}]]></HQMusicUrl>
                            <ThumbMediaId><![CDATA[${options.media_id}]]></ThumbMediaId>
                         </Music>`;
    }else if(options.msgType === 'news'){
        replyMessage += ` <ArticleCount>${options.content.length}</ArticleCount>
                          <Articles>`;
        options.content.forEach(item => {
            replyMessage += `<item>
                              <Title><![CDATA[${item.title}]]></Title>
                              <Description><![CDATA[${item.description}]]></Description>
                              <PicUrl><![CDATA[${item.picurl}]]></PicUrl>
                              <Url><![CDATA[${item.url}]]></Url>
                            </item>`;
        })
        replyMessage += `</Articles>`;
    }
    replyMessage += `</xml>`;
    // 最终回复给用户的xml数据
    return replyMessage;
}